package com.jiulong.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiulong.dao.TFavoriteMapper;
import com.jiulong.model.TAccount;
import com.jiulong.model.TAccountExample;
import com.jiulong.model.TFavorite;
import com.jiulong.model.TFavoriteExample;
import com.jiulong.model.TGift;
import com.jiulong.model.TOrder;
import com.jiulong.model.TOrderExample;
import com.jiulong.service.AccountService;
@Service
public class AccountServiceImpl implements AccountService{
	@Autowired
	com.jiulong.dao.TAccountMapper tAccountMapper;
	@Autowired
	
	com.jiulong.dao.TOrderMapper TOrderMapper;
	@Autowired
	com.jiulong.dao.TFavoriteMapper TFavoriteMapper;
	@Override
	public TAccount findAccountbyId(String openid) {
	
		TAccountExample example=new TAccountExample();
		example.createCriteria().andOpenidEqualTo(openid);
		
		List<TAccount> list=tAccountMapper.selectByExample(example);
		System.out.println(list.get(0).getAccount());
		return list.get(0);		
	}

	@Override
	public TOrder findOrderbyId(String account) {
		
		TOrderExample example=new TOrderExample();
		example.createCriteria().andAccountEqualTo(account);
		List<TOrder>list= TOrderMapper.selectByExample(example);
		System.out.println("我的订单回显到前端页面的价格"+list.get(0).getAmount());
		System.out.println(list.get(0).getAccount());
		return list.get(0);	
	}
//通过订单号查询出订单状态
	@Override
	public TOrder findOrderbytrade(String out_trade_no) {
		TOrderExample example=new TOrderExample();
		example.createCriteria().andRemarkEqualTo(out_trade_no);
		List<TOrder>list= TOrderMapper.selectByExample(example);
		System.out.println("微信返回的价格"+list.get(0).getAmount());
		System.out.println(list.get(0).getAccount());
		return list.get(0);	
	}

//通过订单号查询出核销订单号

	@Override
	public TFavorite findFavoritebytrade(String out_trade_no) {
		TFavoriteExample example=new TFavoriteExample();
		//example.createCriteria().andIdEqualTo(1);
		example.createCriteria().andAccountEqualTo(out_trade_no);
		List<TFavorite>list= TFavoriteMapper.selectByExample(example);
		System.out.println("核销的优惠券号码"+list.get(0).getProductid());
		return list.get(0);	
	}
}
